/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RecipeCellShort.java
 *
 * Created on Feb 2, 2012, 5:35:02 PM
 */
package laboration2.gui;

import java.awt.Component;
import javax.swing.*;
import se.chalmers.ait.dat215.lab2.Recipe;

/**
 *
 * @author arildm
 */
public class RecipeCellShort extends JPanel implements ListCellRenderer {

    /** Creates new form RecipeCellShort */
    public RecipeCellShort() {
        initComponents();
    }
    
    public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected, boolean cellHasFocus) {
        if (value == null || !(value instanceof Recipe)) {
            throw new IllegalArgumentException();
        }
        Recipe recipe = (Recipe) value;
        
        nameLabel.setText(recipe.getName());
        infoLabel.setText(recipe.getCuisine()+", "+recipe.getMainIngredient());
        
        // Fetch default style using default renderer and a dummy list
        ListCellRenderer defaultRenderer = new DefaultListCellRenderer();
        JLabel defaultLabel = (JLabel) defaultRenderer.
            getListCellRendererComponent(new JList(), null, 0, isSelected,
            cellHasFocus);
	setBorder(defaultLabel.getBorder());
        setForeground(defaultLabel.getForeground());
        if (isSelected || index % 2 == 1) {
            setBackground(defaultLabel.getBackground());
        } else {
            setBackground(java.awt.Color.WHITE);
        }
        
        return this;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        spacer = new javax.swing.JLabel();
        nameLabel = new javax.swing.JLabel();
        infoLabel = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(laboration2.Laboration2App.class).getContext().getResourceMap(RecipeCellShort.class);
        spacer.setText(resourceMap.getString("spacer.text")); // NOI18N
        spacer.setName("spacer"); // NOI18N
        spacer.setPreferredSize(new java.awt.Dimension(0, 40));

        nameLabel.setFont(nameLabel.getFont().deriveFont(nameLabel.getFont().getStyle() | java.awt.Font.BOLD));
        nameLabel.setText(resourceMap.getString("nameLabel.text")); // NOI18N
        nameLabel.setName("nameLabel"); // NOI18N

        infoLabel.setText(resourceMap.getString("infoLabel.text")); // NOI18N
        infoLabel.setName("infoLabel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(spacer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nameLabel)
                    .addComponent(infoLabel))
                .addContainerGap(67, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(nameLabel)
                .addGap(0, 0, 0)
                .addComponent(infoLabel))
            .addComponent(spacer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel infoLabel;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JLabel spacer;
    // End of variables declaration//GEN-END:variables
}
